﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Microsoft.Practices.Prism.ViewModel;
using Microsoft.Practices.Prism.Commands;
using System.Linq.Expressions;

namespace BindableAppBarTester
{
    public class MainPageViewModel : NotificationObject
    {
        private bool _showActions;
        private bool _isPlaying;

        private DelegateCommand _playCommand;
        private DelegateCommand _pauseCommand;
        private ICommand _showActionsCommand;        
        private ICommand _shuffleCommand;
        private ICommand _repeatCommand;

        public bool IsPlaying
        {
            get { return _isPlaying; }
            set
            {
                if (_isPlaying != value)
                {
                    _isPlaying = value;
                    PlayCommand.RaiseCanExecuteChanged();
                    PauseCommand.RaiseCanExecuteChanged();
                    RaisePropertyChanged(() => IsPlaying);
                }
            }
        }
        
        public bool ShowActions
        {
            get { return _showActions; }
            set
            {
                if (_showActions != value)
                {
                    _showActions = value;
                    RaisePropertyChanged(() => ShowActions);
                }
            }
        }

        public MainPageViewModel()
        {
            ShowActions = true;
        }

        public ICommand ShowActionsCommand
        {
            get
            {
                if (_showActionsCommand == null)
                {
                    _showActionsCommand = new DelegateCommand<bool>(show => ShowActions = show);
                }

                return _showActionsCommand;
            }
        }

        public DelegateCommand PlayCommand
        {
            get
            {
                if (_playCommand == null)
                {
                    _playCommand = new DelegateCommand(
                        () =>
                            {
                                IsPlaying = true;
                                MessageBox.Show("Playing Music...");
                            },
                        () => !IsPlaying);
                }

                return _playCommand;
            }
        }

        public DelegateCommand PauseCommand
        {
            get
            {
                if (_pauseCommand == null)
                {
                    _pauseCommand = new DelegateCommand(
                        () => 
                            {
                                IsPlaying = false;
                                MessageBox.Show("Music Paused!");
                            },
                        () => IsPlaying);
                }

                return _pauseCommand;
            }
        }

        public ICommand ShuffleCommand
        {
            get
            {
                if (_shuffleCommand == null)
                {
                    _shuffleCommand = new DelegateCommand(() => MessageBox.Show("Shuffle Tracks..."));
                }

                return _shuffleCommand;
            }
        }

        public ICommand RepeatCommand
        {
            get
            {
                if (_repeatCommand == null)
                {
                    _repeatCommand = new DelegateCommand(() => MessageBox.Show("Repeat Track..."));
                }

                return _repeatCommand;
            }
        }        
    }
}
